<template>
  <div class="to-top-container" @click="handleClick" v-show="isShow">
      TOP
  </div>
</template>

<script>
export default {
  name: "ToTop",
  data() {
    return {
      isShow: false
    }
  },
  methods: {
    handleScroll(dom) {
      if(!dom) {
        this.isShow = false;
        return;
      }
      this.isShow = dom.scrollTop > 600;
    },
    handleClick() {
      // 点击的时候，触发事件， 设置滚动条高度为 0；
      this.$eventBus.$emit("setMainScroll", 0);
    }
  },
  created() {
    this.$eventBus.$on("mainScroll", this.handleScroll)
  },
  destroyed() {
    this.$eventBus.$off("mainScroll", this.handleScroll)
  }
}
</script>

<style scoped lang="less">
@import "~@/styles/var.less";
.to-top-container {
  background: @primary;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  position: fixed;
  z-index: 99;
  right: 50px;
  bottom: 50px;
  cursor: pointer;
  line-height: 50px;
  color: #fff;
  text-align: center;
}
</style>
